package com.nosnow.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nosnow.common.utils.R;
import com.nosnow.edu.entity.EduCourse;
import com.nosnow.edu.entity.EduTeacher;
import com.nosnow.edu.service.EduCourseService;
import com.nosnow.edu.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author by bingHeng
 * @version 1.0
 * @Create 2020/4/18 19:54
 */

@RestController
@RequestMapping("/edu/front/teacher")
public class IndexFrontController {

    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduTeacherService eduTeacherService;

    /**
     * 查询前8条热门课程，查询前4条名师
     * @return
     */
    @GetMapping("index")
    public R index() {
        // 1. 查询前8条热门课程
        QueryWrapper<EduCourse> courseWrapper = new QueryWrapper<>();
        courseWrapper.orderByDesc("id");
        courseWrapper.last("limit 8");
        List<EduCourse> eduCourses = eduCourseService.list(courseWrapper);

        //2. 查询前4位名师
        QueryWrapper<EduTeacher> teacherWrapper = new QueryWrapper<>();
        teacherWrapper.orderByDesc("id").last("limit 4");
        List<EduTeacher> eduTeachers = eduTeacherService.list(teacherWrapper);
        return R.ok().data("eduList", eduCourses).data("teacherList", eduTeachers);
    }
}
